package Function;

import java.util.ArrayList;

public class ListIntegerStack implements IntegerStack {
	private int capacity;
	private int top = 0;
	private Integer[] arrStack;

	public ListIntegerStack(int capacity) {
		this.capacity = capacity;
		this.arrStack = new Integer[capacity];
	}

	public Integer push(Integer item){
		if (item == null)
			return null;
		if (top == this.capacity) {
			throw new FullStackException();
			
		} 
		arrStack[top++] = item;
		return item;

	}

	@Override
	public Integer pop() {
		if (top == 0) {
			throw new EmptyStackException();
		}
		return arrStack[--top];
	}

	@Override
	public Integer peek(){
		if (top == 0){
			throw new EmptyStackException();
		}
		return arrStack[top-1];
	}

	@Override
	public boolean empty() {
		if(top==0)
			return true;
		return false;
	}

	@Override
	public int size() {
		return arrStack.length;
	}

}
